layui.use(['form', 'table', 'laydate', 'layarea', 'tableSelect'], function () {
    let $ = layui.jquery,
        form = layui.form,
        laydate=layui.laydate,
        table = layui.table;

    let id_arr=$.getQueryVariable('id_arr')


    /*订单列表*/
    table.render(
        {
            elem: '#currentTableId',
            url: '/admin/SaleOrderData/index?action=ajax&id_arr='+id_arr,
            method: 'post',
            data:{id:1},
            parseData: function (res) { //res 即为原始返回的数据
                $('#ToTalPrice').html(res.totalprice);
                $('#TotalNum').html(res.totalnum);
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: [ 'exports', 'print'],
            cols: [
                [
                    {field: 'create_time', title: '日期时间' },
                    // {field: 'mo_id', title: '订单id' },
                    {field: 'total_price', title: '订单金额' },
                    {field: 'total_num', title: '商品数量' },
                    {field: 'pay_type', title: '收款方式' },
                    {field: 'pay_price', title: '实际支付'},
                    {field: 'data_status', title: '订单状态',templet:"#Tplstatus"},
                    {title: '操作', toolbar: '#currentTableBar'},
                ],
            ],

            limits: [10, 15, 20, 25, 30, 50, 100],
            limit: 10,
            page: true,
            skin: 'line,row',
            done: function (res, curr, count) {

            }
        }
    );



    table.on('tool(currentTableFilter)', function (obj) {

        let data = obj.data;

        if (obj.event === 'orderdetail') {
            let index = layer.open({
                title: '订单详情',
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: '/admin/SaleOrderData/DataDetail?mo_id=' + data.mo_id,
                end: function () {
                    /*删除session无用图片*/
                    $.ajax({
                        url: '/admin/order/clearSession',
                        type: 'post',
                        dataType: 'json',
                    });
                }
            });
            $(window).on("resize", function () {
                layer.full(index);
            });
            return false;
        }

    });


    // 监听搜索操作
    form.on('submit(data-search-btn)', function (data) {
        submitInfo();
    });
    form.on('select(selectInfo)', function (data) {
        submitInfo();
    });

    $("input[name='keywords']").on('blur',function (re) {
        submitInfo();
    })

    // 开始日期
    let insShelf = laydate.render({
        elem: '#create_time'
        // , min: 0
        // , calendar: true
        , type: 'datetime'
        , done: function (value, date) {

            submitInfo()

        }
    });

    function submitInfo() {
        let param = {};
        let t = $('#formInfo [name]');

        $.each(t, function () {
            param[this.name] = this.value;
        });

        //let result = JSON.stringify(d);

        //执行搜索重载
        table.reload('currentTableId', {
            page: {
                curr: 1
            }
            , where: {
                //searchParams: result
                param
            }
        }, 'data');
        return false;
    };
});
